package shop.controller;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import product.dto.Gyms;
import product.params.SportsAddParam;
import product.params.UserInvitationCodeParam;
import product.service.GymsServiceI;
import product.service.SportsServiceI;

import java.util.List;

@RestController
@RequestMapping("Sports")
public class SportsController {
    @DubboReference(version = "1.0.0")
    SportsServiceI sportsServiceI;
    @DubboReference(version = "1.0.0" ,timeout = 100000000)
    GymsServiceI gymsServiceI;
    /**
     * 增加用户运动
     * */
    @PostMapping
    public String addSports(@RequestBody SportsAddParam param) {
        System.out.println(param.toString());
        sportsServiceI.addSports(param);

        return "addSports";
    }

    /**
     * 提交用户id与邀请验证码,将用户与健身房绑定,并将用户升级为vip
     * */
    @PostMapping("bindGym")
    public String bindGym(@RequestBody UserInvitationCodeParam param) {
      return  gymsServiceI.setUserGymByInvitationCode(param.getInvitationCode(), param.getUserId());
      }

      /**
       * 获取与我们有合作的所有健身房
       * */
      @GetMapping("getGyms")
      public List<Gyms> getGyms() {
          return gymsServiceI.getAllGyms();
      }
      /**
       * 获取用户已经绑定的健身房
       * */
      @GetMapping("getUserGym")
      public List<Gyms> getUserGym(int userId) {
          return gymsServiceI.getGymsByUserId(userId);
      }
}
